package com.village.friend.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.village.friend.constant.PolicyType;
import com.village.friend.dto.request.PolicyAddDto;
import com.village.friend.dto.request.PolicyInitDto;
import com.village.friend.dto.request.PolicyListDto;
import com.village.friend.dto.request.PolicyUpdateDto;
import com.village.friend.entity.UserPolicy;
import com.village.friend.mapper.UserPolicyMapper;
import com.village.friend.service.UserPolicyService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 会员缴费政策表 服务实现类
 * </p>
 *
 * @author yl
 * @since 2021-08-23
 */
@Service
public class UserPolicyServiceImpl extends ServiceImpl<UserPolicyMapper, UserPolicy> implements UserPolicyService {

    @Override
    public List<UserPolicy> queryParam(PolicyListDto param) {
        QueryWrapper<UserPolicy> qw = new QueryWrapper<>();
        qw.eq("policy_type", param.getPolicyType());
        qw.orderByDesc("vip_level");
        qw.orderByAsc("id");
        return list(qw);
    }

    @Override
    public UserPolicy findOneByTypeAndMonths(String type, Integer grade) {
        QueryWrapper<UserPolicy> qw = new QueryWrapper<>();
        qw.eq("policy_type", type);
        qw.eq("months", grade);
        return getOne(qw);
    }

    @Override
    public UserPolicy findOneByTypeAndPrice(String type, Integer amount) {
        QueryWrapper<UserPolicy> qw = new QueryWrapper<>();
        qw.eq("policy_type", type);
        qw.eq("price", amount);
        return getOne(qw);
    }


}
